Return to doc.sitecore.com

Valid for Sitecore 5.2, 5.1.1
  Abort
Prev Next

The Abort method halts further execution of the chain.  When the current method call returns, no other data providers in the chain will be called.  For instance, if a data provider wants to make sure that its result is used as the final result, it can use code like the following:

  public override ItemDefinition GetItemDefinition(ID itemID,
  CallContext context) {
    ItemDefinition item = GetMyItemFromTheDatabase();
 
    if (item != null) {
      context.Abort();
 
      return item;
    }
 
    return null;
  }

To understand what happens when the method call above returns, it is necessary to understand the way DataManager calls the data providers in the chain. It works like shown in the pseudo-code below:

DataManager.GetItem(...) {
  CallContext context = new CallContext(this);
 
  foreach(DataProvider provider in providers) {
    ItemDefinition item = provider.GetItemDefinition(...);
 
    if (item != null) {
      context.CurrentResult = item;
    }
   
    if (context.Aborted) {
      break;
    }
  }
 
  return context.CurrentResult as ItemDefinition;

There is one gotcha in the code. If the data provider that aborted the chain returns null, then context.CurrentResult is not updated, and the result from the DataManager will actually be the previous value of context.CurrentResult.

If a data provider wishes to force a return value of null, it should use the technique described in the next section.


Prev Next